extends "ChaInfo.gd"
	
func _extInit():
	._extInit()
	attInfox.maxHp = 500
	attInfox.atk = 50
	attInfox.mgiAtk = 200
	attInfox.def = 10
	attInfox.dod = 80
	lv = 1             #等级的设置
	atkEff = "atk_dang" #攻击时的特效
	isSumm = true

var flag = false
func _onNormalAtk(cha):
	._onNormalAtk(cha)
	changeExp(2)
	
func _onKillChara(atkInfo):
	._onKillChara(atkInfo)
	changeExp(4)

func _onDeath(atkInfo):
	._onDeath(atkInfo)
	changeExp(-2)
	if summoner != null and not summoner.isDeath:
		summoner.onSummDeath(atkInfo)

func _castCdSkill(id):
	._castCdSkill(id)
	changeExp(4)
	if id == "duliSk3":
		duliSk3()

#空域辅助
func duliSk3():
	var chas = getAllChas(2)
	chas.sort_custom(sys, "sortByHp")
	var dmg = (att.atk + att.mgiAtk) * 1.5
	for i in range(3):
		if i >= chas.size() : break
		healCha(chas[i], dmg)		

func changeExp(num):
	if summoner == null or summoner.lv < 3:return
	summoner.crewExp = max(0, summoner.crewExp + num*summoner.summExpBonus)
	if summoner.crewExp >= 100:
		var exLv = 0
		summoner.crewExp = 0
		summoner.crewLv = min(summoner.crewMaxLv + exLv, summoner.crewLv + 1)

func updateAtt():
	if team == 2:return
	if summoner.crewLv != 0:
		var p = 0.12
		attEx.atkL += (summoner.crewLv)*p
		attEx.mgiAtkL += (summoner.crewLv)*p
		attEx.defL += (summoner.crewLv)*p
		attEx.maxHpL += (summoner.crewLv)*p

		# var p2 = 0
		# if summoner.crewLv >= 10:
		# 	p2 = 0.2
		# 	match type:
		# 		sys.CharaClass.FIGHT:
		# 			attEx.dod = p2 * 100
		# 			attEx.defR = p2
		# 			attEx.maxHpL = p2
		# 		sys.CharaClass.CAS:
		# 			attEx.spd = p2
		# 			attEx.defR = p2
		# 		sys.CharaClass.TBF:
		# 			attEx.cd = p2
		# 			attEx.defR = p2
		plusHp(att.maxHp)
		upAtt()
		

func getInfo():
	var res = "\n"
	res += "[color=#33ff33]血量：[color=#DC143C]{hp}/{maxHp}[/color]  机动：[color=#DC143C]{dod}[/color]\n".format({"hp":int(att.hp), "maxHp":int(att.maxHp), "dod":att.dod})

	if mainFlag:
		res += "主炮·{name}  射速：[color=#BDB76B]{spd}%[/color] 伤害:[color=#BDB76B]{dmg}[/color] 射程:[color=#BDB76B]{range}[/color]\n".format({"name":mainName, "spd":int((1+att.spd)*100), "dmg":mainDmg, "range":att.atkRan})
	if torpFlag:
		res += "鱼雷·{name}  装填：[color=#BDB76B]{cd}[/color]秒 伤害:[color=#BDB76B]{dmg}[/color]\n".format({"name":torpName, "cd":torpCd, "dmg":torpDmg})

	res += "炮击：[color=#DC143C]{atk}[/color]  雷击：[color=#DC143C]{mgiAtk}[/color]  冷却：[color=#DC143C]{cd}%[/color]  装甲：[color=#DC143C]{def}({defL}%)[/color]\n".format({"atk":int(att.atk), "mgiAtk":int(att.mgiAtk), "cd":int(att.cd*100), "def":int(att.def), "defL":int(att.def / (100 + att.def) * 100)})

	res += "暴击：[color=#DC143C]{cri}%[/color]  爆伤：[color=#DC143C]{criR}%[/color]  吸血：[color=#DC143C]{suck}%[/color]  穿透：[color=#DC143C]{pen}%[/color]\n".format({"cri":int(att.cri*100), "criR":int((att.criR+2)*100), "suck":int(att.suck*100), "pen":int(att.pen)})

	for i in skillStrs:
		var tmp = i.rsplit("{tmpName}")
		i = tmp[0]
		if tmp.size() == 2:
			var skName = tmp[1]
			var skData = skillData.get(skName)
			if skData != null:
				var cd = skData.get("cd")
				var id = skData.get("id")
				var sk
				if id != null:
					sk = getSkill(id)
				if sk != null:
					i = i.replace("{cd}", utils.floatScale(sk.cd/(1+att.cd)))
				var dmg = self.getSkillEffect(skName)
				if dmg != null:
					i = i.replace("{damage}", int(dmg))
		res += i + "\n"
	# res = appendMeta(res)
	return "[color=%s]%s[/color]" % [config.itemGradeColors[lv - 1], chaName] + res

func chaInfo(cha):
	var charaInfos = []
	for i in sys.get_node("/root/topUi").get_children():
		if i.name.find("charaInfoMsg") > -1:charaInfos.append(i)
	var charaInfo = charaInfos.pop_back()
	charaInfo.get_node("Button").hide()

#新建技能统一封装
func addSkill(text, name, id = null, cd = null, index = -1):
	if id != null and cd != null:
		addCdSkill(id, cd)
	var skillText = "{color}{text}[/color]{tmpName}".format({"text":text, "color":skillColors[3]})
	skillText += name
	if index == -1:
		addSkillTxt(skillText)
	else:
		skillStrs[index] = skillText

	if skillData.has(name):
		skillData.get(name).text = skillText
	else:
		skillData[name] = {"text":skillText, "name":name, "id":id, "cd":cd}


func _onAtkChara(atkInfo):
	._onAtkChara(atkInfo)
	atkInfo.hurtVal *= (1 + summoner.att.air*0.003)

func _onHurt(atkInfo):
	._onHurt(atkInfo)
	atkInfo.hurtVal *= (300.0 / (300 + summoner.att.air))

func postInit():
	if lv == 2:
		attInfox.maxHp *= 1.1
		attInfox.atk *= 1.1
		attInfox.mgiAtk *= 1.1
		attInfox.def += 10
	elif lv == 3:
		attInfox.maxHp *= 1.2
		attInfox.atk *= 1.25
		attInfox.mgiAtk *= 1.25
		attInfox.def += 20
	elif lv == 4:
		attInfox.maxHp *= 1.2
		attInfox.atk *= 1.5
		attInfox.mgiAtk *= 1.5
		attInfox.def += 30
	upAtt()	